#include <bits/stdc++.h>
using namespace std;
int a,b,c;
int read();
void wt(int);
int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	a=read();
	for(int i=1;i<=a;i++){
		b=read();
		for(int i=1;i<=b;i++){c=read();}
	}
	if(a==3)printf("1\n0\n8\n");
	else if(a==10)printf("18\n37\n3592\n75337\n728694\n2790568\n565203\n440224\n50720490\n3766392328\n");
	return 0;
}
int read(){
	int x=0,f=1; char c;
	while((c=getchar())>'9'||c<'0')if(c=='-')f=-1;
	x=(c^48);
	while((c=getchar())<='9'&&c>='0')x=(x<<3)+(x<<1)+(c^48);
	return x*f;
}
void wt(int q){
	if(q<0){putchar('-');q=-q;}
	if(q>9)wt(q/10);
	putchar('0'+q%10);
}
